# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html

import pymysql

class OnePipeline(object):
    def process_item(self, item, spider):
        return item


def dbHandle():
    conn = pymysql.connect(
        host='115.159.93.82',
        user='root',
        passwd='website',
        charset='utf8',
        use_unicode=False,
        db='blogN'
    )
    return conn

class DouPipeline(object):

    def proccess_item(self, item, spider):
        # spider.d
        dbObject = dbHandle()
        cursor = dbObject.cursor()
        sql = 'insert into movies(html, title, content, thunders, cover, onlinetime, updatetime)values(%s, %s, %s, %s, %s, %s, %s)'
        effect_row = cursor.execute(sql, (item['html'], item['title'], item['content'], item['thunders'], item['cover'], item['onlinetime'], item['updatetime']))
        dbObject.commit();
        cursor.close();
        dbObject.close();

